< previous page page_89 next page >

Page 89
Save and run the project again. This time, after you edit the text box, click the Update button. Now, move the record pointer forward to the next record and then back to the record you edited. What do you see? The record was not updated! Remember, in the OpenDB procedure you set the ReadOnly property of the database to True and turned on the ReadOnly value of the Options property. Now modify the OpenDB procedure and change the ReadOnly property to False and drop the dbReadOnly and dbDenyWrite constants from the Options property by setting the Options property to 0.
When you rerun the program, you can now edit the text box, restore the old value with the Restore button, or save the new value with the Update button. You can also save the new value by moving the record pointer.
This last behavior of the data control can cause some problems. What if you changed a field and didn't want to save the changes, but instead of clicking the Restore button, you moved to the next record? You would change the database and never know it! In the next section, you'll use one of the data control's events to help you avoid just such a situation.
Data Control Events
All Microsoft Windows programs contain events. These events occur each time the computer senses that a user clicks a button or passes the mouse over an object on the form, or when any other process occurs. When an event takes place, the Windows operating system sends a message that tells all processes currently running that something has happened. Windows programs can then ''listen" for messages and act, based on their programming code, when the right message comes along.
In Visual Basic, you can create program code that executes each time a specific event occurs. There are three data control events that relate to database functions:
·Reposition
·Validate
·Error
The Reposition event occurs each time the data control moves to a new position in the Dynaset. The Validate event occurs each time a data control leaves the current record. The Error event occurs each time a database error occurs when the arrow buttons on the data control are used to move the record pointer. Visual Basic automatically creates procedure headers and footers for all the events associated with a control. When you place a data control on your form, Visual Basic creates the procedures Data1_Reposition, Data1_Validate, and Data1_Error.

 
< previous page page_89 next page >

If you like this book, buy it!